﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace Security
{
	public class SystemInfo
	{
		unsafe internal static string[] GetMoc()
		{
			string[] str = new string[3];
			ManagementClass mcCpu = new ManagementClass("win32_Processor");
			ManagementObjectCollection mocCpu = mcCpu.GetInstances();
			foreach (ManagementObject m in mocCpu)
			{
				str[0] = m["ProcessorId"].ToString();
			}

			ManagementClass mcHD = new ManagementClass("win32_logicaldisk");
			ManagementObjectCollection mocHD = mcHD.GetInstances();
			foreach (ManagementObject m in mocHD)
			{
				if (m["DeviceID"].ToString() == "C:")
				{
					str[1] = m["VolumeSerialNumber"].ToString();
					break;
				}
			}

			ManagementClass mcMAC = new ManagementClass("Win32_NetworkAdapterConfiguration");
			ManagementObjectCollection mocMAC = mcMAC.GetInstances();
			foreach (ManagementObject m in mocMAC)
			{
				if ((bool)m["IPEnabled"])
				{
					str[2] = m["MacAddress"].ToString();
					break;
				}
			}

			return str;
		}
	}
}



//using System;
//using System.Management;
//using System.IO;
//using System.Runtime.InteropServices;
//using System.Security.Cryptography;
//using System.Text;
//using Microsoft.Win32; 


//namespace TestDemo.Hardware
//{
//class Program
//{
//static void Main(string[] args)
//{


//Program p = new Program();
//Console.WriteLine(p.GetCpuInfo());
//Console.WriteLine(p.GetHDid());
//Console.WriteLine(p.GetMoAddress());


//string strbNumber = string.Empty;
//ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_baseboard");
//foreach (ManagementObject mo in mos.Get())
//{
//strbNumber = mo["SerialNumber"].ToString();
//Console.WriteLine("baseboard ID: " + strbNumber);
////Console.WriteLine("baseboard ID" + mo["SerialNumber"]);  
//Console.WriteLine("主板制造商:" + mo["Manufacturer"]);
//Console.WriteLine("型号:" + mo["Product"]);
//break;
//}  



//Console.Read();
//}


///// <summary> 
///// 获取cpu序列号 
///// </summary> 
///// <returns>string </returns> 
//public string GetCpuInfo()
//{
//string cpuInfo = "";
//ManagementClass cimobject = new ManagementClass("Win32_Processor");
//ManagementObjectCollection moc = cimobject.GetInstances();
//foreach (ManagementObject mo in moc)
//{
//cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
//}
//return cpuInfo.ToString();
//}


///// <summary> 
///// 获取硬盘ID 
///// </summary> 
///// <returns>string </returns> 
//public string GetHDid()
//{
//string HDid = "";
//ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
//ManagementObjectCollection moc1 = cimobject1.GetInstances();
//foreach (ManagementObject mo in moc1)
//{
//HDid = (string)mo.Properties["Model"].Value;
//}
//return HDid.ToString();
//}

///// <summary> 
///// 获取网卡硬件地址 
///// </summary> 
///// <returns>string </returns> 
//public string GetMoAddress()
//{
//string MoAddress = "";
//ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
//ManagementObjectCollection moc2 = mc.GetInstances();
//foreach (ManagementObject mo in moc2)
//{
//if ((bool)mo["IPEnabled"] == true)
//MoAddress = mo["MacAddress"].ToString();
//mo.Dispose();
//}
//return MoAddress.ToString();
//}  
//}
//}
